﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Xuanren_FrontEnd.Common;
using Xuanren_FrontEnd.Model;

namespace Xuanren_FrontEnd.Controllers
{
    public class HomeController : Controller
    {
        private XuanrenTherapyEntities db = new XuanrenTherapyEntities();
        // GET: Home
        public ActionResult Index()
        {
            //关于我们
            var about =db.About.SingleOrDefault();
            ViewBag.About=about;
            //商品列表
            ViewBag.Product=db.Product.Take(6).Where(x=>x.is_ShowHome == "1").OrderByDescending(x=>x.create_time);

            //新闻列表
            ViewBag.News=db.News.Take(4).Where(x=>x.isShowHome=="1").OrderByDescending(x=>x.create_time);
            return View();
        }
        
        public ActionResult About()
        {
            return View();
        }
        public ActionResult Contact()
        {
            About about= db.About.SingleOrDefault();
            return View(about);
        }

        public ActionResult Comment() {
            return View();
        }
        public ActionResult CreateImageCode(int id=1)
        {
            string code= RadomCode.GenerateCode(4);

            Session["AuthCode"] = code;

            byte[] bytes= RadomCode.CreateImage(code,80);

            return File(bytes,"jpg");
        }

        public ActionResult Login() {
            return View();
        }

        // public ActionResult Settlement() {
        //     return View();
        // }
    }
}